
<template>
	<view>
		<view class="doctor-outbox"
		style="background-color: #fffae8;">
			<image class="doctor-icon" :src="chooseyisheng.photo"></image>
			<view class="doctor-info" >
				<text class="doctor-name text-position">{{chooseyisheng.name}}</text>
				<text class="gray-text text-position">{{keshiname}}</text>
				<text class="gray-text text-position">{{chooseyisheng.shanchang.substring(0,15)}}</text>
			</view>
		</view>
		<span class="choose-item-info">
			已选日期：{{chooseDateValue}}
			（{{dateToday==chooseDateValue?'今':checkXIngqi(chooseDateValue)}}）
		</span>
		<view class="time-list">
			<view class="item-time-list" v-for="(e1,i1) in yuyuebiaoTimeList" :key="e1"
			@click="chooseTime(e1.yuyuecan,e1.number,e1.time)">
			<image class="icon" :src="'/static/jhimage/time.png'"></image>
			{{e1.number}}号<span class="yuyue-date-button">{{e1.time}}</span>
			<span class="jiage">￥12.00</span>
			<span class="yuyue-button" v-if="e1.yuyuecan">可预约</span>
			<span class="dyuyue-button" v-else>不可约</span>
			</view>
		</view>
		<view class="loading">{{loadingText}}</view>
	</view>
</template>

<script>
	import {error} from '@/common/js/errorTips.js'
	import {
		findyishengBykeshi,
		findKeshiByid,
		findavaliablePanban,
		findAYishengBuKeshi,
		findADateList,
		chooseDoctorByDateKeAKeshi,
		getKeshiName,
		findyishengByid,
		findADateListByyIsheng,
		findAYuyuelTimes,
	} from '@/common/api/jh/doctor.js'
	
	var _self = 1,
		timer = null;
	export default {
		// 到达底部时会自动获取新数据
		onReachBottom: function() {
			
		},
		data() {
			return {
				doctorList: [],
				yishengpaibanList: [],
				dateList: [],
				doctorDateList :[],
				dateDoctorList: [],
				loadingText: '到底啦...',
				page: 1,
				specialId: 0,
				outpatientId: 0,
				iconURL: '/static/appointment/',
				tabs: [{
					name:'按时间',
					image:'/static/jhimage/date.png'
				},
				{
					name:'按医生',
					image:'/static/jhimage/doctor.png'
				}],
				activeIndex: 0,
				dateclass: [],
				dateclass2: [],
				keshi: '',
				
				chooseDateValue: '',
				dateToday: '',
				chooseYishengValue: '',
				//add
				oldinfo: {},
				chooseyisheng:{},
				keshiname: '',
				yuyuebiaoTimeList:[]
			}
		},
		onLoad(){
			if(uni.getStorageSync('isAlreadyLogin')){
				this.getBaseData()
				this.getNow()
			}else{
				error("请先登录！")
			}
		},
		methods: {
			getBaseData(){
				var info = JSON.parse(uni.getStorageSync("yuyue1"))
				var object= {
					yisheng :info.yisheng,
					date: info.date,
					keshi: info.keshi
				}
				this.oldinfo = object	
				this.chooseDateValue = info.date
				this.findyishengByid(info.yisheng)
				this.getKeshiName(info.keshi)
				this.findAYuyuelTimes(info.yisheng,info.date)
			},
			findAYuyuelTimes(yisheng,date){
				findAYuyuelTimes(yisheng,date).then(res => {
					console.log(JSON.stringify(res.data))
					this.yuyuebiaoTimeList  = res.data
				}).catch(() => {
					error('网络故障!')
				})
			},
			findyishengByid(id){
				findyishengByid(id).then(res => {
					this.chooseyisheng = res.data
				}).catch(() => {
					error('网络故障!')
				})
			},
			
			chooseTime(yuyuecan,number,time){
				if(yuyuecan){
					console.log(number+time)
					if(uni.getStorageSync('isAlreadyLogin')){
						var object= {
							time :time,
							number: number,
							price: '12'
						}
						uni.setStorageSync("yuyue2",JSON.stringify(object))
						uni.navigateTo({
							url: '/pages/yuyue/insureYuyue'
						})
					}else{
						error("请先登录！")
					}
				}
			},
			getKeshiName(keshi){
				getKeshiName(keshi).then(res => {
					console.log(res.data)
					this.keshiname = res.data
				}).catch(() => {
					uni.hideLoading()
					error('网络故障')
				})
			},
			getNow(){
				var date = new Date();
				var month = Number(date.getMonth())+1
				console.log((Number(month)<=9)+"===============month<=9")
				var nmonth = ""
				if((Number(month)<=9)){
					nmonth = "0"+String(month)
				}else{
					nmonth = String(month)
				}
				var ndate = ""
				if((Number(date.getDate())<=9)){
					ndate = "0"+String(date.getDate())
				}else{
					ndate = String(date.getDate())
				}
				var ff = nmonth+"/"+ndate+"/"+date.getFullYear()
				this.dateToday = ff
			},
			checkXIngqi(e){
				var date = new Date(e);
				var week = date.getDay();
				var str = ""; 
				if (week == 0) { 
				        str = "日"; 
				} else if (week == 1) { 
				        str = "一"; 
				} else if (week == 2) { 
				        str = "二"; 
				} else if (week == 3) { 
				        str = "三"; 
				} else if (week == 4) { 
				        str = "四"; 
				} else if (week == 5) { 
				        str = "五"; 
				} else if (week == 6) { 
				        str = "六"; 
				} 
				return str;
			},
		},
	}
</script>

<style lang="scss">
	@import '@/common/scss/common.scss';
	@import '@/common/scss/doctor.scss';
	.text-position{
		width: 90%;
		height: 50%;
		display: flex;
		align-items: center;
	}
	.text-position2{
		width: 100%;
		height: 60px;
		display: flex;
		align-items: center;
	}
	.time-list{
		margin: 5px;
		color: #000000;
	}
	.icon {
		@include icon-size(40rpx, 40rpx);
		margin-right: 50rpx;
		margin-left: 20rpx;
		margin-top: 10rpx;
	}
	.item-time-list{
		border:1rpx solid #f0f0f0;
		margin: 15rpx;
		border-radius: 10rpx;
		font-size: 15px;
	}
	.item-time-list2{
		border:1rpx solid #f0f0f0;
		margin: 15rpx;
		border-radius: 10rpx;
		font-size: 18px;
		color: #00aaff;
	}
	.onclickitem{
		color: #00aaff;
	}
	.gray-text{
		@include font-style(12px, 500, $gray-color);
	}
	.doctor-name{
		@include font-style(18px, bold, #000000);
	}
	.loading {
		text-align: center;
		line-height: 80px;
		font-family: '宋体';
		color: #a6a6a6;
	}
	// 关于顶部导航栏的
	.weui-tab__content {
		// padding-top: 60px;
		text-align: center;
	}
	.yuyue-date-button{
		margin-left: 8%;
	}
	.jiage{
		color:#ffaa00;
		font-size: 13px;
		margin-left: 20px;
		font-family: '宋体';
		margin-top: 12px;
	}
	.yuyue-button{
		color:#00aaff;
		font-size: 13px;
		float: right;
		margin-right: 2%;
		font-family: '宋体';
		margin-top: 12px;
	}
	.dyuyue-button{
		color:#a6a6a6;
		font-size: 13px;
		float: right;
		margin-right: 2%;
		font-family: '宋体';
		margin-top: 12px;
	}
	.choose-item-info{
		color:#00aaff;
		font-size: 15px;
		margin-left: 20px;
	}
</style>
